package com.monitor.display_platform.core.common;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * 全局异常处理，避免返回直接返回错误信息，对Controller层进行拦截，返回需要的内容
 * */
@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalDefultExceptionHandler {
    /**
     * 系统异常
     * */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ServerResponse errorParamException(Exception ex){
        log.error("出现了系统异常{}",ex.getStackTrace());
        log.error("详细错误信息如下",ex);
        return ServerResponse.fail(ex.getMessage());
    }
}
